<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue refs和nextTick</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@3"></script>
  </head>
  <body>
    <div id="app">
      <h1>Vue实例</h1>
      <hr />
      <h1 ref="txt">当前的num为:{{num}}</h1>
      <button @click="clickHandle">点一下</button>
    </div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            num: 1
          };
        },
        methods: {
          clickHandle() {
            this.num++;
            // console.log(this.$refs.txt.innerText);
            // $nextTick 是一个内置的全局api，可以在其回调函数中获取dom的最新值
            this.$nextTick(() => {
              console.log(this.$refs.txt.innerText);
            });
          },
        },
      });
      app.mount("#app");
    </script>
  </body>
</html>
